// const BASE_URL = 'http://192.168.199.238:1115'
//服务器地址
let isOnline = true
// let isOnline = false

let version = wx.getAccountInfoSync().miniProgram.envVersion


if( version == 'trial' || version == 'release')  {
  isOnline = true
}

let BASE_URL = ''
if (isOnline) {
  // 正式
  BASE_URL = "https://mail.glack.net/wmjapi";
} else {
  // 测式
  BASE_URL = 'http://localhost:1115'
}


const wxRequest = ({ url, data = {}, method = 'get' }) => {
  if (!url.startsWith('/')) {
    url = '/' + url
  }
  return new Promise((resolve, reject, findlly) => {
    wx.request({
      url: BASE_URL + url,
      method,
      data,
      success: resolve,
      fail: reject,
      complete: findlly
    })
  })
}

module.exports = {
  wxRequest,
  BASE_URL,
  isOnline
}